$codeplexdir=$Env:codeplex_edxlsharp_aws
$codeplexdir=$codeplexdir+'\EDXLSharp_AWSRouter'
$netdir=$Env:windir
$netinstall=$netdir+'\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe'
$DESvc=$codeplexdir+'\DEProcessing\bin\Debug\DEProcessing.exe'
$DeleteService = 0


# Constants (You could change these, but why?)
$DEProcessingSQSQueueName = "icnet-deprocessing"
$ContentProcessingSQSQueueName = "icnet-contentprocessing"
$FederationProcessingSQSQueueName = "icnet-federationprocessing"
$EDXLDynamoTableName = "EDXLCache"
$DynamoContentTableName = "ContentCache"
$DynamoFeedTableName = "FeedCache"
$ValueListDynamoTableName = "ValueLists"
$RulesDynamoTableName = "Rules"


if($DeleteService -eq 1)
{
	Write-Host $DESvc
	Write-Host $netinstall $DESvc
	taskkill /f /IM DEProcessing.exe
	& $netinstall /u $DESvc
}

$queues = Get-SQSQueue
Write-Host $queues
$found = 0
foreach ($queue in $queues)
{
	if($queue -eq $DEProcessingSQSQueueName)
	{
		$found = 1
		$url = Get-SQSQueueUrl -QueueName $queue
		break
	}
}

if ($found = 1)
{
	Remove-SQSQueue -QueueUrl $url -Force
}

$found = 0
foreach ($queue in $queues)
{
	if($queue -eq $ContentProcessingSQSQueueName)
	{
		$found = 1
		$url = Get-SQSQueueUrl -QueueName $queue
		break
	}
}

if ($found = 1)
{
	Remove-SQSQueue -QueueUrl $url -Force
}

$found = 0
foreach ($queue in $queues)
{
	if($queue -eq $FederationProcessingSQSQueueName)
	{
		$found = 1
		$url = Get-SQSQueueUrl -QueueName $queue
		break
	}
}

if ($found = 1)
{
	Remove-SQSQueue -QueueUrl $url -Force
}

$tables = Get-DDBTables
Write-Host $tables
$found = 0
foreach ($table in $tables)
{
	if ($table -eq $EDXLDynamoTableName)
	{
		$found = 1
		break
	}
}

if ($found = 1)
{
	Remove-DDBTable -TableName $EDXLDynamoTableName -Force
}

$found = 0
foreach ($table in $tables)
{
	if ($table -eq $DynamoContentTableName)
	{
		$found = 1
		break
	}
}

if ($found = 1)
{
	Remove-DDBTable -TableName $DynamoContentTableName -Force
}

$found = 0
foreach ($table in $tables)
{
	if ($table -eq $DynamoFeedTableName)
	{
		$found = 1
		break
	}
}

if ($found = 1)
{
	Remove-DDBTable -TableName $DynamoFeedTableName -Force
}

$found = 0
foreach ($table in $tables)
{
	if ($table -eq $ValueListDynamoTableName)
	{
		$found = 1
		break
	}
}
if($found -eq 1)
{
	Remove-DDBTable -TableName $ValueListDynamoTableName -Force
}

$found = 0
foreach ($table in $tables)
{
	if ($table -eq $RulesDynamoTableName)
	{
		$found = 1
		break
	}
}
if($found -eq 1)
{
	Remove-DDBTable -TableName $RulesDynamoTableName -Force
}